#include <assert.h>
#include <inttypes.h>
#include <stdio.h>

enum DatabaseError {
    // Denotes an error when the user attempted a write operation.
    IsReadOnly = 1,
    // Denotes an error when the user should read the error code for what it was.
    IOError = 2,
    // Denotes an error when the user should run a repair tool to recover it.
    FileCorrupted = 3,
};

extern int32_t
    db_error_code(enum DatabaseError* error);

void assert_db_error_code(enum DatabaseError arg, int32_t expected_result)
{
    int32_t result = db_error_code(&arg);

    assert(expected_result == result);
}

void test_api()
{
    {
        enum DatabaseError arg = IsReadOnly;
        int32_t expected_result = 1;
        assert_db_error_code(arg, expected_result);
    }
    {
        enum DatabaseError arg = IOError;
        int32_t expected_result = 2;
        assert_db_error_code(arg, expected_result);
    }
    {
        enum DatabaseError arg = FileCorrupted;
        int32_t expected_result = 3;
        assert_db_error_code(arg, expected_result);
    }
}

int main(void)
{
    enum DatabaseError arg = IsReadOnly;
    int32_t result = db_error_code(&arg);
    printf("(result: %" PRIu32 ")\n",
           result);

    test_api();

    return 0;
}
